package com.itheima.demo02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/16 16:59
 */
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(12306);
        //创建线程池;
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,
                10,
                30,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        while (true) {
            //等待服务器连接;
            Socket accept = ss.accept();
            MyRunnable mr = new MyRunnable(accept);
            pool.submit(mr);
        }
        //ss.close();
    }
}
